import 'package:enterprise_v6_app/app/components/custom_app_bar.dart';
import 'package:enterprise_v6_app/app/core/values/colors.dart';
import 'package:enterprise_v6_app/app/core/values/gaps.dart';
import 'package:enterprise_v6_app/app/modules/application/basic_information/productive_process/major_hazard_base/major_hazard_base_item_detail/major_hazard_base_item_detail_controller.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

///重大危险源详情
class MajorHazardBaseItemDetailPage extends StatelessWidget {
  MajorHazardBaseItemDetailPage({super.key});

  final controller = Get.put(MajorHazardBaseItemDetailController());

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        backgroundColor: AppColors.bg_color_grey,
        appBar: CustomAppBar(
          titleText: '重大危险源详情',
        ),
        body: GetBuilder(
          init: controller,
          builder: (_) {
            return SingleChildScrollView(
              child: Column(
                children: [
                  _titleBg(),
                  Container(
                    height: 40.w,
                    width: double.infinity,
                    color: const Color(0xFFF4F7FF),
                    alignment: Alignment.centerLeft,
                    padding: EdgeInsets.only(left: 40.w),
                    child: Text(
                      controller.entity.riskObjectName!,
                      style: TextStyle(
                        fontSize: 16.sp,
                      ),
                    ),
                  ),
                  Container(
                    height: 1.w,
                    color: const Color(0xFFDEE5FD),
                  ),
                  Container(
                    color: Colors.white,
                    padding: EdgeInsets.only(left: 40, right: 40, top: 20.w, bottom: 20.w),
                    child: Column(
                      children: [
                        _rowData('危险源等级：', _getHazardRankText(controller.entity.hazardRank!)),
                        AppGaps.vGap12,
                        _rowData('危险源分类：', controller.entity.hazardTypeLabel!),
                        AppGaps.vGap12,
                        _rowData('危险源简称：', controller.entity.hazardSimpleName!),
                        AppGaps.vGap12,
                        _rowData('危险源编码：', controller.entity.hazardCode!),
                        AppGaps.vGap12,
                        _rowData('R值：', controller.entity.rvalue!),
                        AppGaps.vGap12,
                        _rowData('地址：', controller.entity.address!),
                        AppGaps.vGap12,
                        _rowData('经度：', controller.entity.longitude!),
                        AppGaps.vGap12,
                        _rowData('纬度：', controller.entity.latitude!),
                        AppGaps.vGap12,
                        _rowData('投用日期：', controller.entity.activationTime!),
                        AppGaps.vGap16,
                        _divider(),
                        AppGaps.vGap16,
                        _rowData('周边防护目标最近距离：', controller.entity.closestDistance!.toString(), width: 200.w),
                        AppGaps.vGap12,
                        _rowData('外边界500米范围人数估算：', controller.entity.numberEstimation!.toString(), width: 200.w),
                        AppGaps.vGap12,
                        _rowData('是否在化工园区内：', controller.entity.inChemicalIndustrialPark! == 0 ? '是' : '否', width: 200.w),
                        AppGaps.vGap12,
                        _rowData('所属化工园区名称：', controller.entity.parkName!, width: 200.w),
                        AppGaps.vGap12,
                        _rowData('生产能力：', controller.entity.productionCapacity!, width: 200.w),
                        AppGaps.vGap12,
                        _rowData('是否涉及重点监管工艺：', controller.entity.isKeynote! == 0 ? '是' : '否', width: 200.w),
                        Visibility(
                            visible: controller.entity.isKeynote! == 0,
                            child: Column(
                              children: [
                                AppGaps.vGap12,
                                _rowData('涉及重点监管工艺名称：', controller.entity.keyProcessesName!, width: 200.w),
                              ],
                            )),
                        AppGaps.vGap16,
                        _divider(),
                        AppGaps.vGap16,
                        _rowData('主要负责人：', controller.entity.mainHead!, width: 150.w),
                        AppGaps.vGap12,
                        _rowData('主要负责人联系方式：', controller.entity.mainHeadPhone!, width: 150.w),
                        AppGaps.vGap12,
                        _rowData('技术负责人：', controller.entity.tecHead!, width: 150.w),
                        AppGaps.vGap12,
                        _rowData('技术负责人联系方式：', controller.entity.tecHeadPhone!, width: 150.w),
                        AppGaps.vGap12,
                        _rowData('操作负责人：', controller.entity.controlHead!, width: 150.w),
                        AppGaps.vGap12,
                        _rowData('操作负责人联系方式：', controller.entity.controlHeadPhone!, width: 150.w),
                      ],
                    ),
                  ),
                ],
              ),
            );
          },
        ));
  }

  /// 获取危险等级
  /// 危险等级（0：非重大危险源；1：一级；2：二级；3：三级；4：四级；）
  String _getHazardRankText(String hazardRank) {
    switch (hazardRank) {
      case '1':
        return '一级';
      case '2':
        return '二级';
      case '3':
        return '三级';
      case '4':
        return '四级';
      default:
        return '非重大危险源';
    }
  }

  /// 标题背景分隔栏
  Widget _titleBg() {
    return Column(
      children: [
        AppGaps.vGap12,
        Container(
          height: 2.w,
          color: const Color(0xFF587DF5),
        ),
      ],
    );
  }

  ///分割线
  Widget _divider() {
    return Container(
      width: double.infinity.w,
      height: 1.w,
      decoration: const BoxDecoration(
          gradient: LinearGradient(begin: Alignment.centerRight, end: Alignment.centerLeft, colors: [
        Color(0x005C6DFF),
        Color(0xFD5C6DFF),
        Color(0x005C6DFF),
      ])),
    );
  }

  Widget _rowData(String name, String value, {double? width, Alignment alignment = Alignment.centerLeft}) {
    return Row(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        SizedBox(
          width: width ?? 110.w,
          child: Text(
            name,
            style: TextStyle(
              fontSize: 12.sp,
              height: 1.2,
              fontWeight: FontWeight.w400,
              color: const Color(0xFF7C7D93),
            ),
          ),
        ),
        Expanded(
          child: Align(
            alignment: alignment,
            child: Text(
              value,
              style: TextStyle(
                fontSize: 12.sp,
                height: 1.2,
                color: const Color(0xFF495061),
                fontWeight: FontWeight.w400,
              ),
            ),
          ),
        )
      ],
    );
  }
}
